#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#define PLUGIN_VERSION "1.0.0"

public Plugin:myinfo = 
{
	name = "NoBlock for nades",
	author = "-sang-",
	description = "NoBlock for nades",
	version = PLUGIN_VERSION,
	url = "http://steamcommunity.com/id/-sang-"
};

new g_CollisionOffset;

public OnPluginStart()
{
	CreateConVar("sm_noblock_for_nades_version", PLUGIN_VERSION, "NoBlock For Nades Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_UNLOGGED|FCVAR_DONTRECORD|FCVAR_REPLICATED|FCVAR_NOTIFY);
	g_CollisionOffset = FindSendPropInfo("CBaseEntity", "m_CollisionGroup");
}

public OnEntityCreated(entity, const String:classname[])
{
	if (StrEqual(classname, "hegrenade_projectile")
		|| StrEqual(classname, "smokegrenade_projectile")
		|| StrEqual(classname, "flashbang_projectile"))
	{
		SetEntityNonBlocking(entity);
		SDKHook(entity, SDKHook_StartTouch, OnNadeTouch);
	}
}

SetEntityBlocking(entity)
{
	PrintToChatAll("blocking");
	SetEntData(entity, g_CollisionOffset, 0, 1, true);
}

SetEntityNonBlocking(entity)
{
	PrintToChatAll("non blocking");
	SetEntData(entity, g_CollisionOffset, 2, 1, true);	
}

public OnNadeTouch(nade, entity)
{
	if(entity > 0 
		&& entity <= MaxClients )
	{
		new client = GetEntPropEnt(nade, Prop_Send, "m_hThrower");
		if(GetClientTeam(client) == GetClientTeam(entity))
		{
			SetEntityNonBlocking(nade);
		}
		else
		{
			SetEntityBlocking(nade);
		}
	}
}